//
//  TestOperationView.m
//  MKUITestApp
//
//  Created by 苏尚进 on 2022/3/2.
//  Copyright © 2022 moon. All rights reserved.
//

#import "TestOperationView.h"

@implementation TestOperationView

- (id)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        self.preButton = [[TestFunButton alloc] initWithTitle:@" < "];
        [self addSubview:self.preButton];
        //
        self.nextButton = [[TestFunButton alloc] initWithTitle:@" > "];
        [self addSubview:self.nextButton];
        //
        
        self.leftButton = [[TestFunButton alloc] initWithTitle:@" -1 "];
        [self addSubview:self.leftButton];
        //
        self.stepLabel = [[UILabel alloc] init];
        self.stepLabel.text = @"Step:";
        self.stepLabel.font = [UIFont systemFontOfSize:12];
        self.stepLabel.textColor = [UIColor mk_colorWithLight:[UIColor blackColor]];
        [self addSubview:self.stepLabel];
        //
        self.rightButton = [[TestFunButton alloc] initWithTitle:@" +1 "];
        [self addSubview:self.rightButton];
        //
        self.cycleButton = [[TestFunButton alloc] initWithTitle:@"UnCycle"];
        [self.cycleButton setTitle:@"Cycle" forState:UIControlStateSelected];
        [self addSubview:self.cycleButton];
        //
        self.refreshButton = [[TestFunButton alloc] initWithTitle:@"刷新"];
        [self addSubview:self.refreshButton];
        //
        self.refreshBgButton = [[TestFunButton alloc] initWithTitle:@"后台刷新"];
        [self addSubview:self.refreshBgButton];
        //
        self.addButton = [[TestFunButton alloc] initWithTitle:@"+分组"];
        [self addSubview:self.addButton];
        //
        self.deleteButton = [[TestFunButton alloc] initWithTitle:@"-分组"];
        [self addSubview:self.deleteButton];
        //
        MKUIFlowLayoutConstraint *f1 = [[MKUIFlowLayoutConstraint alloc] initWithItems:@[self.preButton,self.nextButton,self.leftButton,self.stepLabel,self.rightButton] constraintParam:(MKUIFlowLayoutConstraintParam_H_C_L) contentInsets:(MKUIEdgeInsetsMakeSameEdge(0)) interitemSpacing:5];
        MKUIFlowLayoutConstraint *f2 = [[MKUIFlowLayoutConstraint alloc] initWithItems:@[self.cycleButton,self.refreshButton,self.refreshBgButton,self.addButton,self.deleteButton] constraintParam:(MKUIFlowLayoutConstraintParam_H_C_L) contentInsets:(MKUIEdgeInsetsMakeSameEdge(0)) interitemSpacing:5];
        self.line1layout = f1;
        self.line2ayout = f2;
        //
        self.flowlayout = [[MKUIFlowLayoutConstraint alloc] initWithItems:@[f1,f2] constraintParam:(MKUIFlowLayoutConstraintParam_V_C_L) contentInsets:(MKUIEdgeInsetsMakeSameEdge(0)) interitemSpacing:5];
    }
    return self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    CGRect bounds = self.bounds;
    self.flowlayout.bounds = bounds;
    [self.flowlayout layoutItemsWithResizeItems:YES];
}
- (CGSize)sizeThatFits:(CGSize)size{
    CGSize s = [self.flowlayout sizeThatFits:size resizeItems:YES];
    s.width = size.width;
    return s;
}
@end
